package com.study.controller;


import com.study.service.communication.AuthorityFeignClient;
import com.study.service.communication.UseRestTemplateService;
import com.study.service.communication.UseRibbonService;
import com.study.vo.JwtToken;
import com.study.vo.UsernameAndPassword;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微服务通信
 */

@Slf4j
@RestController
@RequestMapping("/commuication")
public class CommuicationController {

    @Autowired
    private UseRestTemplateService useRestTemplateService;

    @Autowired
    private UseRibbonService useRibbonService;

    @Autowired
    private AuthorityFeignClient authorityFeignClient;

    @PostMapping("/rest-template")
    private JwtToken getTokenFromAuthorityService(
            @RequestBody UsernameAndPassword usernameAndPassword){
        return useRestTemplateService.getTokenFromAuthorityService(usernameAndPassword);
    }

    @PostMapping("/rest-template-load-balancer")
    private JwtToken getTokenFromAuthorityServiceWithloadBalancer(
            @RequestBody UsernameAndPassword usernameAndPassword){
        return useRestTemplateService.getTokenFromAuthorityServiceWithloadBalancer(usernameAndPassword);
    }

    @PostMapping("/ribbon")
    private JwtToken getTokenFromAuthorityServiceByRibbon(
            @RequestBody UsernameAndPassword usernameAndPassword){
        return useRibbonService.getTokenFromAuthorityServiceByRibbon(usernameAndPassword);
    }

    @PostMapping("/feign")
    private JwtToken getTokenByFeign(
            @RequestBody UsernameAndPassword usernameAndPassword){
        return authorityFeignClient.getTokenByFeign(usernameAndPassword);
    }
}
